﻿Public Class frmEditRepairation
    Dim Strsql As String
    Public Primary_code As String
    Dim _mysql As New ClsSQLhelper
#Region "Function"
    Sub Load_Repair_status()
        Try
            Strsql = "Select repair_status_id,repair_status_name from repair_status"
            Dim DT_Budget As New DataTable
            DT_Budget = _mysql.GetMYSQLDataTable(Strsql, "repair_status")
            With Me.CboRepairation
                .DataSource = DT_Budget
                .DisplayMember = "repair_status_name"
                .ValueMember = "repair_status_id"
            End With
        Catch ex As Exception
            With frmDebug
                .lblFormName.Text = Me.Name
                .lblFunctionName.Text = "Load_Repair_status"
                .MemoErr_Description.Text = ex.Message
                .MemoSQL.Text = Strsql
                .ShowDialog()

            End With
        End Try

    End Sub
    Sub Load_Data()
        Try
            Strsql = "Select * from repairation where repair_id = " & Primary_code
            Dim DT_Reair As New DataTable
            DT_Reair = _mysql.GetMYSQLDataTable(Strsql, "repairation")
            Me.CboRepairation.SelectedValue = DT_Reair.Rows(0).Item("repair_status")
            Me.DtpDateSent.DateTime = DT_Reair.Rows(0).Item("repair_date")
            Me.DtpDateReceive.DateTime = DT_Reair.Rows(0).Item("return_date")
            Me.MemoRemark.Text = DT_Reair.Rows(0).Item("remark").ToString
            Me.TxtRepairPlace.Text = DT_Reair.Rows(0).Item("repair_place").ToString
        Catch ex As Exception
            With frmDebug
                .lblFormName.Text = Me.Name
                .lblFunctionName.Text = "Load_Data"
                .MemoErr_Description.Text = ex.Message
                .MemoSQL.Text = Strsql
                .ShowDialog()

            End With
        End Try
    End Sub
#End Region
    Private Sub frmEditRepairation_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Load_Repair_status()
        Load_Data()
    End Sub

    Private Sub BtnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnOK.Click
        Try
            Strsql = "Update repairation set repair_status = " & Me.CboRepairation.SelectedValue & " , "
            Strsql = Strsql & " repair_date = '" & Pn_Framework.MysqlDateTimeFormat(DtpDateSent.DateTime, False) & "' , "
            Strsql = Strsql & " repair_place = '" & Me.TxtRepairPlace.Text & "',"
            Strsql = Strsql & " return_date = '" & Pn_Framework.MysqlDateTimeFormat(DtpDateReceive.DateTime, False) & "' where repair_id = " & Primary_code

            Select Case (_mysql.MySQLExecute(Strsql))
                Case -1
                    frmDebug.lblFormName.Text = Me.Name
                    frmDebug.lblFunctionName.Text = "OK_Button_Click"
                    frmDebug.MemoErr_Description.Text = "SQL Error กรุณาตรวจสอบคำสั่ง"
                    frmDebug.MemoSQL.Text = Strsql
                    frmDebug.ShowDialog()
                    Exit Sub
                Case Else
                    MsgBox("ปรับปรุงข้อมูลเรียบร้อยแล้ว", MsgBoxStyle.Information, "ผลการปรับปรุงข้อมูล")
            End Select
            DialogResult = Windows.Forms.DialogResult.OK
        Catch ex As Exception
            With frmDebug
                .lblFormName.Text = Me.Name
                .lblFunctionName.Text = "BtnOK_Click"
                .MemoErr_Description.Text = ex.Message
                .MemoSQL.Text = Strsql
                .ShowDialog()
            End With
        End Try
    End Sub

    Private Sub BtnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnCancel.Click

        DialogResult = Windows.Forms.DialogResult.Cancel
        Me.Dispose()
    End Sub

    Private Sub GroupControl1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles GroupControl1.Paint

    End Sub
End Class